<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="models.Course"%>
<%@page import="models.User"%>
<%@page import="service.UserDao"%>
<%@page import="org.hibernate.Session"%>
<%@page import="service.HibernateUtil"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link href="style/tutor.css" type="text/css" rel="Stylesheet">
        <!-- include jQuery Library From Google Code -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function(){
                //smooth pagina overloop
                $("body").css("display", "none"); 
                $("body").fadeIn("slow");

                function queryTeacher(){
                    var id = $("#teacherList").val();
                    if(id != null){
                        window.location = "/users?teacherID="+id;
                    }
                }
                $("#teacherList").bind("change", queryTeacher);
                
                
                function queryStudent(){
                    var id = $("#userList").val();
                    if(id != null){
                        window.location = "/users?studentID="+id;
                    }
                }
                $("#userList").bind("change", queryStudent);

            });
        </script>

        <jsp:useBean id="inhoud" scope="application" class="models.Bean" />   
        <jsp:setProperty name="inhoud" property="language" value="<%= models.Bean.getLanguage() %>" />
        
        <title>
            Three 2 Learn
        </title>
    </head>
    <body>       
        <div id="wrapper">
            <jsp:include page="adminSidebar.jsp"/>
            <div id="right">   
                <h1>
                    <jsp:setProperty name="inhoud" property="key" value="ManageUsers" />
                    <jsp:getProperty name="inhoud" property="key" /> 
                </h1>
                <div class="box">
                    <h2>
                        <jsp:setProperty name="inhoud" property="key" value="AddOrEditTeacher" />
                        <jsp:getProperty name="inhoud" property="key" />
                    </h2>
                    <div id="teacherContainer">
                        <select id="teacherList" multiple="multiple" style="width:240px; max-height:140px">
                            <c:choose>
                                <c:when test="${not empty teachers}">
                                    <c:forEach var="tempTeacher" items="${teachers}">
                                        <option value="${tempTeacher.userID}">${tempTeacher.userName}</option>
                                    </c:forEach>
                                </c:when>
                            </c:choose>
                        </select>
                    </div>
                    <table width="240px ">
                        <form method="post" action="/users?admin=true">

                            <th colspan="2">
                                <jsp:setProperty name="inhoud" property="key" value="AddOrEditTeacher" />
                                <jsp:getProperty name="inhoud" property="key" />
                            </th>

                            <tr>                    
                                <td>
                                    <jsp:setProperty name="inhoud" property="key" value="Username" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input type="text" value="${chosenTeacher.userName}" name="username"/></td>
                            </tr>
                            <tr>                    
                                <td>
                                    <jsp:setProperty name="inhoud" property="key" value="FirstName" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input type="text" value="${chosenTeacher.firstName}" name="firstname"/></td>
                            </tr>
                            <tr>                    
                                <td>
                                    <jsp:setProperty name="inhoud" property="key" value="LastName" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input type="text" value="${chosenTeacher.lastName}" name="lastname"/></td>
                            </tr>
                            <tr>                    
                                <td>
                                    Email:
                                </td><td><input type="text" value="${chosenTeacher.email}" name="email"/></td>
                            </tr>
                            <tr>
                                <td>Status:</td>
                                <td>

                                    <c:if test="${not empty chosenTeacher}">
                                        <jsp:setProperty name="inhoud" property="key" value="Currently" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                        : ${chosenTeacher.status}</br>
                                        <jsp:setProperty name="inhoud" property="key" value="ChangeTo" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                        :
                                    </c:if>

                                    <select id="status" name ="status">
                                        <option value="Tutor">
                                            <jsp:setProperty name="inhoud" property="key" value="Tutor" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </option>
                                        <option value="Student">Student</option>
                                        <option value="Admin">Admin</option>
                                        <option value="Disabled">
                                            <jsp:setProperty name="inhoud" property="key" value="Disabled" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </option>
                                    </select>
                                </td>
                            </tr>
                            <tr>                                

                                <c:if test="${empty chosenTeacher}">
                                    <td colspan="2">
                                        <input type="submit" value="Add" />
                                    </td>
                                </c:if>
                                <c:if test="${not empty chosenTeacher}">
                                    <td>
                                        <input type="hidden" name="id" value="${chosenTeacher.userID}"/>
                                        <input type="submit" value="Update" />
                                    </td>
                                </c:if>
                        </form>

                        <c:if test="${not empty chosenTeacher}">
                            <form method="post" action="/users?delete=${chosenTeacher.userID}">
                                <td>
                                    <input type="submit" value="Delete" />

                            </form>
                            <form method="post" action="/users?reset=${chosenTeacher.userID}">

                                <input type="submit" value="Reset Password"/>
                                </td>
                            </form>
                        </c:if>
                        </tr>
                    </table>                
                </div>
                <div class="box">
                    <div id="userContainer">
                        <h2>
                            <jsp:setProperty name="inhoud" property="key" value="AddEditUser" />
                            <jsp:getProperty name="inhoud" property="key" />
                        </h2>
                        <select id="userList" multiple="multiple" style="width:240px; max-height:140px">
                            <c:choose>
                                <c:when test="${not empty students}">
                                    <c:forEach var="tempUser" items="${students}">
                                        <option value="${tempUser.userID}">${tempUser.userName}</option>
                                    </c:forEach>
                                </c:when>
                            </c:choose>
                        </select>
                    </div>               
                    <table width="240px ">
                        <form method="post" action="/users?admin=true">
                            <th colspan="2">
                                <jsp:setProperty name="inhoud" property="key" value="AddEditUser" />
                                <jsp:getProperty name="inhoud" property="key" />
                            </th>
                            <tr>                    
                                <td>
                                    <jsp:setProperty name="inhoud" property="key" value="Username" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input type="text" value="${chosenStudent.userName}" name="username"/></td>
                            </tr>
                            <tr>                    
                                <td>
                                    <jsp:setProperty name="inhoud" property="key" value="FirstName" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input type="text" value="${chosenStudent.firstName}" name="firstname"/></td>
                            </tr>
                            <tr>                    
                                <td>
                                    <jsp:setProperty name="inhoud" property="key" value="LastName" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input type="text" value="${chosenStudent.lastName}" name="lastname"/></td>
                            </tr>
                            <tr>                    
                                <td>
                                    Email:
                                </td><td><input type="text" value="${chosenStudent.email}" name="email"/></td>
                            </tr>
                            <tr>
                                <td>Status:</td>
                                <td>
                                    <c:if test="${not empty chosenStudent}">
                                        <jsp:setProperty name="inhoud" property="key" value="Currently" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                        : ${chosenStudent.status}</br>
                                        <jsp:setProperty name="inhoud" property="key" value="ChangeTo" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                        :
                                    </c:if>

                                    <select id="status" name ="status">
                                        <option value="Tutor">
                                            <jsp:setProperty name="inhoud" property="key" value="Tutor" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </option>
                                        <option value="Student">Student</option>
                                        <option value="Admin">Admin</option>
                                        <option value="Disabled">
                                            <jsp:setProperty name="inhoud" property="key" value="Disabled" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </option>
                                    </select>
                                </td>
                            </tr>
                            <tr>                                

                                <c:if test="${empty chosenStudent}">
                                    <td colspan="2">
                                        <input type="submit" value="Add" />
                                    </td>
                                </c:if>  
                                <c:if test="${not empty chosenStudent}">
                                    <td>
                                        <input type="hidden" name="id" value="${chosenStudent.userID}"/>
                                        <input type="submit" value="Update" />
                                    </td>
                                </c:if>
                        </form>
                        <c:if test="${not empty chosenStudent}">
                            <form method="post" action="/users?delete=${chosenStudent.userID}">
                                <td>
                                    <input type="submit" value="Delete" />
                            </form>
                            <form method="post" action="/users?reset=${chosenStudent.userID}">
                                <input type="submit" value="Reset Password"/>
                                </td>
                            </form>
                        </c:if>
                        </tr>
                    </table>  
                </div>                    
            </div>
        </div>
    </body>